package com.snifferx.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.jboss.logging.Logger;

import com.snifferx.domain.AuthorityEntity;
import com.snifferx.domain.UserEntity;
import com.snifferx.managedbeans.RoleAccessBean;

@ManagedBean(name = "tempRoleView")
@SessionScoped
public class TempRoleView {
	private UserEntity user;
	private ArrayList<AuthorityEntity> roles = new ArrayList<AuthorityEntity>();
	private ArrayList<AuthorityEntity> optionalRoles = new ArrayList<AuthorityEntity>();
	private static Logger log = Logger.getLogger(TempRoleView.class);

	public TempRoleView() {
		super();
		log.debug("into TempRoleView default construcotr");
	}

	public TempRoleView(UserEntity userEntity) {
		// invoke the default constructor first then deal with the optional
		// roles
		this();
		/** below create ID by code **/
		// optionalRoles.add(new AuthorityEntity((new Random().nextLong()),
		// "ROLE_ADMINISTRATOR", userEntity));
		// optionalRoles.add(new AuthorityEntity((new Random().nextLong()),
		// "ROLE_VIEW", userEntity));
		// optionalRoles.add(new AuthorityEntity((new Random().nextLong()),
		// "ROLE_GUEST", userEntity));
		// optionalRoles.add(new AuthorityEntity((new Random().nextLong()),
		// "ROLE_USER", userEntity));

		/**create ID by Hibernate(JPA)***/
		optionalRoles.add(new AuthorityEntity("ROLE_ADMINISTRATOR", userEntity));
		optionalRoles.add(new AuthorityEntity("ROLE_VIEW", userEntity));
		optionalRoles.add(new AuthorityEntity("ROLE_GUEST", userEntity));
		optionalRoles.add(new AuthorityEntity("ROLE_USER", userEntity));

		this.setRoles(optionalRoles);
	}

	public UserEntity getUser() {
		return user;
	}

	public void setUser(UserEntity user) {
		this.user = user;
	}

	public ArrayList<AuthorityEntity> getRoles() {
		return roles;
	}

	public void setRoles(ArrayList<AuthorityEntity> roles) {
		this.roles = roles;
	}

	public ArrayList<AuthorityEntity> getOptionalRoles() {
		return optionalRoles;
	}

	public void setOptionalRoles(ArrayList<AuthorityEntity> optionalRoles) {
		this.optionalRoles = optionalRoles;
	}

}
